package com.example.demo.service.impl;

import com.example.demo.entity.StudentInfo;
import com.example.demo.mapper.StudentMapper;
import com.example.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
   @Autowired
   private StudentMapper studentMapper;

    @Override
    public List<StudentInfo> getStudentInfo() {
        List<StudentInfo> studentInfoList = studentMapper.getStudentInfo();
        return studentInfoList;
    }
    @Override
    public StudentInfo getStudentInfoById(Integer id) {
        StudentInfo info = studentMapper.getStudentInfoById(id);
        return info;
    }

    @Override
    public int deleteStudentInfoById(Integer id) {
        int i = studentMapper.deleteStudentInfoById(id);
        return i;
    }

    @Override
    public int insertStudentInfo(StudentInfo studentInfo) {
        int i = studentMapper.insertStudentInfo(studentInfo);
        return i;
    }
    @Override
    public int updateStudentInfo(StudentInfo studentInfo) {
        int i = studentMapper.updateStudentInfo(studentInfo);
        return i;
    }
    @Override
    public PageResult<StudentInfo> getStudentInfoByPage(PageRequest pageRequest) {
        int pageNum = pageRequest.getPageNum();
        int pageSize = pageRequest.getPageSize();
        int offset = (pageNum - 1) * pageSize;

        List<StudentInfo> list = studentMapper.getStudentInfoByPage(offset, pageSize);
        int total = studentMapper.countStudentInfo();

        return new PageResult<>(pageNum, pageSize, total, list);
    }

}
